<template>
  <div class="app-container">
    <el-dialog v-model="drawer5" :direction="'ttb'" size="small" :with-header="false">
      <Find
        class="titleLI"
        :OriginalFilter="{ static: true }"
        :searchImg="false"
        @Launchform="Launchform5"
        :formList="formList"
        @findClicked="findData3"
      />
      <h1 style="margin-top: 10px">费用明细输入</h1>
      <Table
        @currentRow="currentRow2"
        @inputChange="inputChange2"
        :isLoading="isLoading1"
        style="width: 100%"
        :tableHeader="tableHeader1"
        :tableData="disbursementAndSettlementDate"
        :TableHeight="20"
      />
      <JDialog :tableHeader="JTableHeader2" :width="73" @removeOne="removeOne" :unEdit="true" @confirm="confirm2" />
    </el-dialog>
    <!-- <el-card shadow="always" :body-style="{ padding: '5' }">
   
  </el-card> -->

    <Find @clickNumber1="clickNumber1" @Launchform="Launchform" :OriginalFilter="{ static: true }" :formList="formList1" @findClicked="findData" />

    <el-card style="margin-top: 10px" shadow="always" :body-style="{ padding: '5px' }">
      <h1>检核作业</h1>
      <Find
        @Launchform="Launchform1"
        :OriginalFilter="{ static: true }"
        style="margin-bottom: 10px"
        :searchImg="false"
        :formList="formList2"
        @findClicked="findData1"
      />
      <h1>入库明细查询 <span style="font-size: 11px; color: red">点击修改按钮的时候只能选择一项进行修改</span></h1>
      <Table
        :summaryData="summaryData"
        summary
        @currentRow="currentRow"
        @selectList="selectList"
        @inputChange="confirmChange1"
        :isLoading="isLoading"
        :selection="true"
        :tableHeader="tableHeader"
        :tableData="CheckTheDeductionDetailsTableDate"
        :TableHeight="95"
      />
      <PageModule :PageData="{ total, buttonS: true }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
    </el-card>

    <el-dialog v-model="drawer" :direction="'ttb'" size="small" :with-header="false">
      <el-button type="primary" size="default" @click="SubsidyDeductionInquiry2Methods">查询</el-button>
      <el-button type="primary" size="default" @click="drawer1 = true">新增</el-button>

      <Tables
        @deleteRow="deleteRow"
        :deleteButton="true"
        @inputChange="inputChange2"
        :functionList="true"
        :isLoading="isLoading3"
        style="width: 100%"
        :tableHeader="tableHeader2"
        :tableData="SubsidyDeductionInquiryList"
        :TableHeight="75"
      />
    </el-dialog>

    <el-dialog v-model="drawer1" :direction="'ttb'" size="small" :with-header="false">
      <Find :OriginalFilter="{ static: true }" :searchImg="false" @Launchform="Launchform6" :formList="formList7" @findClicked="findData5" />
    </el-dialog>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import fileRequest from '@/utils/fileRequest'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'SubsidizeDeductionOperations'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { ref, onMounted } from 'vue'
import { formateData } from '@/plugins/mixinJ'
import {
  CheckTheDeductionDetails,
  SubsidyDeductionInquiry,
  ElpoyleList,
  CheckOperation,
  disbursementAndSettlement,
  detilList,
  addList,
  SubsidyDeductionInquiry2,
  deleteUser,
  DeductionIncreas,
  deleteList,
  ModificationOfSettlement,
  toLead
} from '@/api/GeneralFinanceDepartment/GeneralFinanceDepartment/SubsidizeDeductionOperations'
import { ElMessage, ElMessageBox } from 'element-plus'
import LoginWork from '@/utils/LoginWork'

// 删除
const currentTableRow = ref('') as any

const removeOne = async () => {
  if (currentTableRow.value === '') {
    return JMessage.warning('请选择需要删除的数据')
  }
  // 向服务器发送请求，更新外派单信息
  const res = (await LoginWork.put(`/mtlCosts/costTempDelete?item=${currentTableRow.value.item}`)) as any
  // 判断请求是否成功
  if (res.code === 200) {
    disbursementAndSettlementMethods()
    JMessage.success(res.message)
  } else {
    JMessage.error(res.message)
  }
}

const currentRow2 = async (row: any) => {
  currentTableRow.value = row
}

const confirm2 = async (obj: any, dialogVisible: any, title: any) => {
  // 打印出obj的值
  const tempList = formateData([obj]) as any
  // 向服务器发送请求，更新外派单信息
  if (title === '添加') {
    obj.amt = Number(obj.qty) * Number(obj.price)

    // 判断指令号是否为空
    if (obj.lotNo === '' || obj.lotNo === null) {
      const res = (await LoginWork.post(`/mtlCosts/costTempAdd`, obj)) as any
      // 判断请求是否成功
      if (res.code === 200) {
        JMessage.success(res.message)
        // 关闭弹出框
        dialogVisible.value = false
        // 重新获取表格数据
        disbursementAndSettlementMethods()
      } else {
        JMessage.error(res.message)
      }
    } else {
      // 判断指令号是否存在
      const res = (await LoginWork.get(`/back/getRyLotCheck?lotNo=${obj.lotNo}`)) as any
      // 判断请求是否成功
      if (res.code === 200) {
        const res = (await LoginWork.post(`/mtlCosts/costTempAdd`, obj)) as any
        // 判断请求是否成功
        if (res.code === 200) {
          JMessage.success(res.message)
          // 关闭弹出框
          dialogVisible.value = false
          // 重新获取表格数据
          disbursementAndSettlementMethods()
        } else {
          JMessage.error(res.message)
        }
      } else {
        JMessage.error(res.message)
      }
    }
  }
}

const JTableHeader2 = ref([
  {
    type: 'selectJV2',
    width: 300,
    label: '指令号',
    prop: 'lotNo',
    options: [] as any,
    allowC: true
  },
  {
    width: '400',
    label: '费用描述',
    prop: 'costDesc'
  },
  {
    width: '80',
    label: '单位',
    prop: 'costUnit'
  },
  {
    width: '80',
    label: '数量',
    prop: 'qty'
  },
  {
    width: '80',
    label: '单价',
    prop: 'price'
  },
  {
    width: '150',
    label: '备注',
    prop: 'remark'
  }
])

const getSelectList = async () => {
  const res = (await LoginWork.put(`/back/getRyLots`, {
    pageSize: 99999,
    pageNum: 1
  })) as any
  res.data.forEach((item: any) => {
    JTableHeader2.value[0].options?.push({
      value: item,
      label: item
    })
  })
}

const summaryData = ref<any>([
  {
    index: 11,
    num: 0
  },
  {
    index: 14,
    num: 0
  }
])

// 导入
const toLeadMethods = async (file: any) => {
  try {
    const result = await toLead(file, addListParms.value)
    if (result.code === 200) {
      formList.value.forEach((item: any) => {
        item.inputValue = ''
        item.dateValue = ''
        item.selectValue = ''
      })
      CheckTheDeductionDetailsMethods()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('导入失败请重试')
  }
}

const upload = () => {
  const fileType = ['xls', 'xlsx']

  const inputFile = document.createElement('input')

  const maxFileSizeMb = 2

  const maxFilesSizeBytes = maxFileSizeMb * 1024 * 1024

  inputFile.type = 'file'

  inputFile.style.display = 'none'

  document.body.appendChild(inputFile)

  inputFile.addEventListener('change', function () {
    const files = inputFile.files as any // 获取文件数组

    const file = files[0] // 获取第一个文件对象

    const fileExtension = file.name.split('.').pop()

    if (!fileType.includes(fileExtension as any)) {
      JMessage.warning('上传的文件格式只能是 xls, xlsx')
      document.body.removeChild(inputFile)
      return false
    }

    if (file.size > maxFilesSizeBytes) {
      JMessage.warning('文件大小不能超过2MB!!!')
      document.body.removeChild(inputFile)
      return
    }

    const formData = new FormData()

    formData.append('file', file) // 添加文件对象及文件名

    toLeadMethods(formData)
  })

  inputFile.click()
}

// 修改结算方式
const choose = ref()

const ModificationOfSettlementParms = ref([])

const ModificationOfSettlementMethods = async () => {
  try {
    const result = await ModificationOfSettlement(choose.value, ModificationOfSettlementParms.value)
    if (result.code === 200) {
      CheckTheDeductionDetailsMethods()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('修改失败')
  }
}

const findData3 = (row: any) => {
  if (row === '增加') {
    if (
      addListParms.value.accountName === '' ||
      addListParms.value.deptNo === '' ||
      addListParms.value.slipDate === '' ||
      addListParms.value.typeNo === '' ||
      addListParms.value.vendorNo === ''
    ) {
      JMessage.warning('数据不完善请完善')
    } else {
      addListMethods()
    }
  }

  if (row === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.dateValue = ''
      item.selectValue = ''
    })
  }
  if (row === '扣款/补贴定义') {
    SubsidyDeductionInquiryMethods()
    drawer.value = true
  }

  if (row === '修改结算方式') {
    if (choose.value === '喜得狼') {
      choose.value = 1
    } else if (choose.value === '荣阳') {
      choose.value = 2
    }
    if (ModificationOfSettlementParms.value.length === 0) {
      JMessage.warning('请勾选需要修改结算方式的数据')
    } else if (choose.value === '') {
      JMessage.warning('请选择结算方式')
    } else {
      ModificationOfSettlementMethods()
    }
  }
}

// 删除
const CheckTheDeductionDetailsMethodsParms = ref({
  ids: []
})

const deleteListMethods = async () => {
  try {
    const result = await deleteList(CheckTheDeductionDetailsMethodsParms.value.ids)
    if (result.code === 200) {
      CheckTheDeductionDetailsMethods()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('删除出错请重试')
  }
}

const handleCloseMateriaLKlcLtvCodeUsage2 = (_done?: () => void) => {
  if (CheckTheDeductionDetailsMethodsParms.value.ids.length === 0) {
    JMessage.warning('请勾选需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除该数据吗?')
      .then(async () => {
        deleteListMethods()
      })
      .catch(() => {})
  }
}

// 扣款新增
const drawer1 = ref(false)

const formList7 = ref([
  {
    type: 'input',
    inputPlaceholder: '类型编码',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '类型名称',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '财务类型',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '新增'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const findData5 = (row: any) => {
  if (row === '新增') {
    if (DeductionIncreasParms.value.typeName === '' || DeductionIncreasParms.value.typeNo === '') {
      JMessage.warning('数据不完整不可添加')
    } else {
      DeductionIncreasMethods()
    }
  }
  if (row === '置空') {
    formList7.value.forEach((item: any) => {
      item.inputValue = ''
    })
  }
}

const Launchform6 = (row: any) => {
  DeductionIncreasParms.value.typeCw = row[2].inputValue
  DeductionIncreasParms.value.typeName = row[1].inputValue
  DeductionIncreasParms.value.typeNo = row[0].inputValue
}

const DeductionIncreasParms = ref({
  typeCw: '',
  typeName: '',
  typeNo: ''
})

const DeductionIncreasMethods = async () => {
  try {
    const result = await DeductionIncreas(DeductionIncreasParms.value)
    if (result.code === 200) {
      SubsidyDeductionInquiry2Methods()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('新增失败请重试')
  }
}

// 删除
const deleteRow = (row: any) => {
  parmsList.value = row.row
  handleCloseMateriaLKlc5()
}

const parmsList = ref()

const handleCloseMateriaLKlc5 = () => {
  ElMessageBox.confirm('确认要删除数据吗?')
    .then(async () => {
      deleteUserMethods()
    })
    .catch(() => {})
}

const deleteUserMethods = async () => {
  try {
    const result = await deleteUser(parmsList.value)
    if (result.code === 200) {
      SubsidyDeductionInquiry2Methods()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('删除失败')
  }
}

// 扣款补贴查询
const isLoading3 = ref(false)

const SubsidyDeductionInquiry2Methods = async () => {
  isLoading3.value = true
  try {
    const result = await SubsidyDeductionInquiry2()
    SubsidyDeductionInquiryList.value = result.map((item: any) => {
      if (item.flag !== '' || item.flag2 !== '' || item.flag3 !== '') {
        item.backgroundColor2 = '#80E080'
      }
      return item
    })
    isLoading3.value = false
  } catch (error) {
    JMessage.error('查询出错请重试')
    isLoading3.value = false
  }
}

// 扣款/补贴定义查询
const drawer = ref(false)

const SubsidyDeductionInquiryList = ref([])

// 增加
const addListParms = ref({
  accountName: '',
  deptNo: '',
  sendNo: '',
  slipDate: '',
  typeName: '',
  typeNo: '',
  vendorName: '',
  vendorNo: ''
})

const Launchform5 = (row: any) => {
  const partList = row[3].selectValue.split(' ')
  addListParms.value.sendNo = row[0].inputValue
  addListParms.value.slipDate = row[1].dateValue
  addListParms.value.deptNo = row[2].selectValue

  addListParms.value.vendorName = partList[2]
  addListParms.value.vendorNo = partList[3]
  addListParms.value.typeName = row[4].selectValue.split(' ')[1]
  addListParms.value.typeNo = row[4].selectValue.split(' ')[0]
  addListParms.value.accountName = row[5].selectValue
  choose.value = row[5].selectValue
}

const addListMethods = async () => {
  try {
    const result = await addList(addListParms.value)
    if (result.code === 200) {
      CheckTheDeductionDetailsMethods()
      disbursementAndSettlementMethods()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('增加出错请重试')
  }
}

// 修改按钮
const inputChange2 = async (row: any) => {
  try {
    const res = (await LoginWork.put('/mtlCosts/costTempUpdate', row)) as any
    if (res.code === 200) {
      JMessage.success('修改成功')
      disbursementAndSettlementMethods()
    } else {
      JMessage.error(res.message)
    }
  } catch (error) {
    JMessage.error('修改失败请重试')
  }
}

// 修改
const slipNoList = ref('')

const slipNoListA = ref('')

const isLoading1 = ref(true)

const currentRow = (row: any) => {
  slipNoList.value = row.id
  slipNoListA.value = ''
}

const detilListMethods = async () => {
  try {
    const result = await detilList(slipNoList.value)
    if (result.code === 200) {
      disbursementAndSettlementMethods()
      CheckTheDeductionDetailsMethods()
      slipNoList.value = ''
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('修改出错请重试')
  }
}

const handleCloseMateriaLKlcLtvCodeUsage1 = (_done?: () => void) => {
  ElMessageBox.confirm('确认要修改该数据吗?')
    .then(async () => {
      detilListMethods()
    })
    .catch(() => {})
}

// 费用明细输入
const disbursementAndSettlementDate = ref([])

const disbursementAndSettlementMethods = async () => {
  isLoading1.value = true
  try {
    const result = await disbursementAndSettlement()
    disbursementAndSettlementDate.value = result.dtos.map((item: any) => {
      item.change = 'Y'
      item.disableConfirm = true
      return item
    })
    isLoading1.value = false
  } catch (error) {
    JMessage.error('费用明细输入出错')
    isLoading1.value = false
  }
}

// 检核取消检核
const CheckOperationParms = ref<any>('')

const CheckOperationLst = ref()

const selectList = (row: any) => {
  CheckTheDeductionDetailsMethodsParms.value.ids = row.map((item: any) => {
    return item.id
  })

  ModificationOfSettlementParms.value = row.map((item: any) => {
    const { id, accountName, sysUser } = item

    return { id, accountName, sysUser }
  })
}

const Launchform1 = (row: any) => {
  CheckOperationParms.value = row[0].inputValue
  CheckTheDeductionDetailsParms1.value.financeYymm2 = row[0].inputValue
}

const findData1 = (row: any) => {
  if (row === '记录结算') {
    CheckOperationLst.value = 0
    if (CheckOperationParms.value === '') {
      JMessage.warning('月份或需要结算的数据不可为空')
    } else {
      CheckOperationMethods()
    }
  }

  if (row === '取消记录结算') {
    CheckTheDeductionDetailsParms.value.financeYymm2 = CheckOperationParms.value
    CheckOperationLst.value = 1

    CheckOperationMethods()
  }
  if (row === '删除数据') {
    handleCloseMateriaLKlcLtvCodeUsage2()
  }
}

const CheckOperationMethods = async () => {
  try {
    const result = await CheckOperation(CheckTheDeductionDetailsParms1.value, CheckOperationLst.value)
    if (result.code === 200) {
      CheckTheDeductionDetailsMethods()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('检核作业出错请重试')
  }
}

// 备注信息查询
const confirmChange1 = async (row: any) => {
  const { id, remarkCw } = row
  try {
    const result = await LoginWork.post<any, any>(`/salaryFile/PcCostDetail2UpdateRemarkCw?id=${id}&remarkCw=${remarkCw}`)
    if (result.code === 200) {
      CheckTheDeductionDetailsMethods()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('修改失败请重试')
  }
}

// 员工查询
const ElpoyleListMethods = async () => {
  try {
    let NewArray = []
    let NewArray1 = []

    const result = await ElpoyleList()

    NewArray = result.reduce((arr: any, item: any) => {
      if (item.deptNo && item.deptName) {
        // 只添加非空的 typeName 和 typeNo
        arr.push(item.deptName + ' ' + item.name + ' ' + item.workerId)
      }
      return arr
    }, [])

    NewArray1 = result.reduce((arr: any, item: any) => {
      if (item.deptNo && item.deptName) {
        // 只添加非空的 typeName 和 typeNo
        arr.push(item.deptNo + ' ' + item.deptName + ' ' + item.name + ' ' + item.workerId)
      }
      return arr
    }, [])

    formList1.value[4].selectOptions = EvaluatesTheArrayReturnValue3(NewArray)

    formList.value[3].selectOptions = EvaluatesTheArrayReturnValue3(NewArray1)
  } catch (error) {
    JMessage.error('扣款查询出错')
  }
}

const EvaluatesTheArrayReturnValue3 = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      value: item,
      label: item
    }
  })
}

// 扣款查询
const SubsidyDeductionInquiryMethods = async () => {
  try {
    let NewArray = []

    const result = await SubsidyDeductionInquiry()

    NewArray = result.reduce((arr: any, item: any) => {
      if (item.typeNo && item.typeName) {
        // 只添加非空的 typeName 和 typeNo
        arr.push(item.typeNo + ' ' + item.typeName)
      }
      return arr
    }, [])
    formList1.value[5].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
    formList1.value[21].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
    formList.value[4].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
    SubsidyDeductionInquiryList.value = result.map((item: any) => {
      if (item.flag !== '' || item.flag2 !== '' || item.flag3 !== '') {
        item.backgroundColor2 = '#80E080'
      }
      return item
    })
  } catch (error) {
    JMessage.error('扣款查询出错')
  }
}

const EvaluatesTheArrayReturnValue = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item,
      optionLabel: item
    }
  })
}

const formList2 = ref([
  {
    type: 'input',
    inputPlaceholder: '结算月份',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '记录结算',
    disabled: false
  },
  {
    type: 'button',
    checkboxLabel: '取消记录结算',
    disabled: true
  },
  {
    type: 'button',
    checkboxLabel: '删除数据'
  }
])

// 明细查询
const CheckTheDeductionDetailsParms = ref<any>({
  accountName: '',
  balanceNo: '',
  costDesc: '',
  deptNo: '',
  financeYymm: '',
  flag: 1,
  lotNo: '',
  pageNum: 1,
  pageSize: 40,
  sendNo: '',
  slipDateEnd: '',
  slipDateStart: '',
  slipNo: '',
  sysDateEnd: '',
  sysDateStart: '',
  typeName: '',
  vendorName: ''
})

const clickNumber1 = (row: any) => {
  switch (row) {
    case '0': {
      CheckTheDeductionDetailsParms.value.flag = '1'
      formList2.value[1].disabled = false
      formList2.value[2].disabled = true
      break
    }
    case '1': {
      CheckTheDeductionDetailsParms.value.flag = '4'
      formList2.value[1].disabled = true
      formList2.value[2].disabled = true
      break
    }
    case '2': {
      CheckTheDeductionDetailsParms.value.flag = '3'
      formList2.value[1].disabled = true
      formList2.value[2].disabled = false
      break
    }
    case '3': {
      CheckTheDeductionDetailsParms.value.flag = '2'
      formList2.value[1].disabled = true
      formList2.value[2].disabled = true
      break
    }
    case '4': {
      CheckTheDeductionDetailsParms.value.flag = ''
      formList2.value[1].disabled = true
      formList2.value[2].disabled = true
      break
    }
  }

  CheckTheDeductionDetailsMethods()
}

const Launchform = (val: any) => {
  addListParms.value.typeName = val[21].selectValue.split(' ')[1]
  addListParms.value.typeNo = val[21].selectValue.split(' ')[0]
  addListParms.value.accountName = '荣阳'
  addListParms.value.deptNo = val[3].selectValue

  CheckTheDeductionDetailsParms.value.slipNo = val[0].inputValue
  CheckTheDeductionDetailsParms.value.sendNo = val[1].inputValue

  CheckTheDeductionDetailsParms.value.slipDateStart = val[2].dateValue[0]
  CheckTheDeductionDetailsParms.value.slipDateEnd = val[2].dateValue[1]
  CheckTheDeductionDetailsParms.value.deptNo = val[3].selectValue

  CheckTheDeductionDetailsParms.value.vendorName = val[4].selectValue.split(' ')[1]

  CheckTheDeductionDetailsParms.value.typeName = val[5].selectValue.split(' ')[1]

  CheckTheDeductionDetailsParms.value.accountName = val[6]?.selectValue

  CheckTheDeductionDetailsParms.value.sysDateStart = val[7].dateValue[0]
  CheckTheDeductionDetailsParms.value.sysDateEnd = val[7].dateValue[1]

  CheckTheDeductionDetailsParms.value.lotNo = val[8].inputValue
  CheckTheDeductionDetailsParms.value.financeYymm = val[9].inputValue
  CheckTheDeductionDetailsParms.value.costDesc = val[10].inputValue
  CheckTheDeductionDetailsParms.value.balanceNo = val[11].inputValue

  CheckTheDeductionDetailsMethods()

  CheckTheDeductionDetailsParms1.value.slipNo = val[0].inputValue
  CheckTheDeductionDetailsParms1.value.sendNo = val[1].inputValue

  CheckTheDeductionDetailsParms1.value.slipDateStart = val[2].dateValue[0]
  CheckTheDeductionDetailsParms1.value.slipDateEnd = val[2].dateValue[1]
  CheckTheDeductionDetailsParms1.value.deptNo = val[3].selectValue

  CheckTheDeductionDetailsParms1.value.vendorName = val[4].selectValue.split(' ')[1]

  CheckTheDeductionDetailsParms1.value.typeName = val[5].selectValue.split(' ')[1]

  CheckTheDeductionDetailsParms1.value.accountName = val[6]?.selectValue

  CheckTheDeductionDetailsParms1.value.sysDateStart = val[7].dateValue[0]
  CheckTheDeductionDetailsParms1.value.sysDateEnd = val[7].dateValue[1]

  CheckTheDeductionDetailsParms1.value.lotNo = val[8].inputValue
  CheckTheDeductionDetailsParms1.value.financeYymm = val[9].inputValue
  CheckTheDeductionDetailsParms1.value.costDesc = val[10].inputValue
  CheckTheDeductionDetailsParms1.value.balanceNo = val[11].inputValue
}

// 明细查询
const CheckTheDeductionDetailsParms1 = ref<any>({
  accountName: '',
  balanceNo: '',
  costDesc: '',
  deptNo: '',
  financeYymm: '',
  flag: '',
  lotNo: '',
  pageNum: -1,
  pageSize: -40,
  sendNo: '',
  slipDateEnd: '',
  slipDateStart: '',
  slipNo: '',
  sysDateEnd: '',
  sysDateStart: '',
  typeName: '',
  vendorName: '',
  financeYymm2: ''
})

const CheckTheDeductionDetailsTableDate = ref([])

const isLoading = ref(true)

const CheckTheDeductionDetailsMethods = async () => {
  isLoading.value = true
  try {
    const result = await CheckTheDeductionDetails(CheckTheDeductionDetailsParms.value)
    CheckTheDeductionDetailsTableDate.value = result.list.map((item: any) => {
      if (item.cfmFlag === 'Y') {
        item.backgroundColor2 = '#80E080'
      }
      if (Number(item.amt) < 0) {
        item.red = true
      }
      if (formList2.value[1].disabled === true) {
        item.change = null
      } else {
        item.change = 'Y'
      }

      item.disableConfirm = true

      return item
    })
    total.value = result.total
    summaryData.value[0].num = result.qtyCount
    summaryData.value[1].num = result.amtCount
    isLoading.value = false
  } catch (error) {
    isLoading.value = false
    JMessage.error('入库明细查询出错')
  }
}

const total = ref(0)

const handleSizeChange = (val: number) => {
  CheckTheDeductionDetailsParms.value.pageSize = val
  CheckTheDeductionDetailsMethods()
}

const handleCurrentChange = (val: number) => {
  CheckTheDeductionDetailsParms.value.pageNum = val
  CheckTheDeductionDetailsMethods()
}

onMounted(() => {
  // CheckTheDeductionDetailsMethods()

  SubsidyDeductionInquiryMethods()

  ElpoyleListMethods()

  // disbursementAndSettlementMethods()
})

const formList1 = ref<any>([
  {
    type: 'input',
    inputPlaceholder: '单据号码',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '送货单号',
    inputValue: '',
    inputWidth: '100px'
  },
  {
    type: 'date',
    dateLabel: '单据日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '部门',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionLabel: `荣阳车间`,
        optionValue: `荣阳车间`
      },
      {
        optionKey: 1,
        optionLabel: `荣信研发`,
        optionValue: `荣信研发`
      }
    ]
  },
  {
    type: 'selectJ',
    selectValue: '',
    selectP: '员工',
    selectLabel: '',
    selectOptions: [],
    selectV2Width: '300px'
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '扣款类型',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '结算方式',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionLabel: `荣阳大货`,
        optionValue: `荣阳大货`
      }
    ]
  },
  {
    type: 'date',
    dateLabel: '制单日期',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '指令',
    dateValue: '',
    inputWidth: '110px'
  },
  {
    type: 'input',
    inputPlaceholder: '结算月份',
    inputValue: '',
    inputWidth: '110px'
  },
  {
    type: 'input',
    inputPlaceholder: '费用描述',
    inputValue: '',
    inputWidth: '110px'
  },
  {
    type: 'input',
    inputPlaceholder: '结算单号',
    inputValue: '',
    inputWidth: '110px'
  },
  {
    type: 'radio1',
    checkboxLabel: '未结算',
    label: '0'
  },
  {
    type: 'radio1',
    checkboxLabel: '已结算',
    label: '3'
  },
  {
    type: 'radio1',
    checkboxLabel: '已结算未应付',
    label: '2'
  },
  {
    type: 'radio1',
    checkboxLabel: '已结算已应付',
    label: '1'
  },
  {
    type: 'radio1',
    checkboxLabel: '全部',
    label: '4'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '修改'
  },
  {
    type: 'button',
    checkboxLabel: '导出'
  },
  {
    type: 'button',
    checkboxLabel: '扣款明细',
    bgColor: '#1890FF'
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '扣款/补贴类型',
    selectLabel: '',
    selectOptions: []
  },
  // {
  //   type: 'select',
  //   selectValue: '',
  //   selectP: '结算方式',
  //   selectLabel: '',
  //   selectOptions: [
  //     {
  //       optionKey: 1,
  //       optionLabel: `喜得狼`,
  //       optionValue: `喜得狼`
  //     },
  //     {
  //       optionKey: 1,
  //       optionLabel: `荣阳`,
  //       optionValue: `荣阳`
  //     }
  //   ]
  // },
  {
    type: 'button',
    checkboxLabel: '导入'
  }
])

const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '单据号',
    inputValue: ''
  },
  {
    type: 'dateSingle',
    dateLabel: '单据日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '部门',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionLabel: `荣阳车间`,
        optionValue: `荣阳车间`
      },
      {
        optionKey: 1,
        optionLabel: `荣信研发`,
        optionValue: `荣信研发`
      }
    ]
  },
  {
    type: 'selectJ',
    selectValue: '',
    selectP: '员工',
    selectLabel: '',
    selectOptions: [],
    selectV2Width: '300px'
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '扣款/补贴类型',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '结算方式',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionLabel: `喜得狼`,
        optionValue: `喜得狼`
      },
      {
        optionKey: 1,
        optionLabel: `荣阳`,
        optionValue: `荣阳`
      }
    ]
  },
  {
    type: 'button',
    checkboxLabel: '增加'
  },
  {
    type: 'button',
    checkboxLabel: '扣款/补贴定义'
  },
  {
    type: 'button',
    checkboxLabel: '修改结算方式'
  },

  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const drawer5 = ref(false)

const findData = async (a: any) => {
  if (a === '扣款明细') {
    disbursementAndSettlementMethods()
    getSelectList()
    drawer5.value = true
  }
  if (a === '置空') {
    formList1.value.forEach((item: any) => {
      item.inputValue = ''
      item.dateValue = ''
      item.selectValue = ''
    })
  }

  if (a === '修改') {
    if (slipNoList.value === '') {
      JMessage.warning('请选择需要修改的数据')
    } else if (slipNoListA.value === '') {
      handleCloseMateriaLKlcLtvCodeUsage1()
    } else {
      JMessage.warning('请选择扣款/补贴为空的数据进行修改')
    }
  }

  if (a === '导出') {
    const res = (await fileRequest.post(`/salaryFile/PcCostDetail2Export`, CheckTheDeductionDetailsParms.value)) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    const FileName = decodeURI(res.headers['content-disposition'].split(`filename=`)[1])
    link.download = FileName //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }

  if (a === '导入') {
    if (addListParms.value.typeNo === '') {
      JMessage.warning('扣款类型资料为空')
      return
    }
    if (addListParms.value.deptNo === '') {
      JMessage.warning('部门不能为空')
      return
    }
    if (addListParms.value.accountName === '') {
      JMessage.warning('结算方式不能为空')
      return
    }
    upload()
  }
}

// 表格数据

const tableHeader = ref([
  {
    label: '单据号码',
    prop: 'slipNo',
    backgroundColor2: true,
    change: true
  },
  {
    label: '单据日期',
    prop: 'slipDate',
    change: true
  },
  {
    label: '制单日期',
    prop: 'sysDate',
    change: true
  },
  {
    label: '部门',
    prop: 'deptNo',
    change: true
  },
  {
    label: '指令号',
    prop: 'lotNo',
    change: true
  },
  {
    label: '扣款/补贴类型',
    prop: 'typeName',
    change: true
  },
  {
    label: '工号',
    prop: 'vendorNo',
    change: true
  },
  {
    label: '员工',
    prop: 'vendorName',
    change: true
  },
  {
    label: '单据号',
    prop: 'sendNo',
    change: true
  },
  {
    label: '类型描述',
    prop: 'costDesc',
    change: true
  },
  {
    label: '数量',
    prop: 'qty',
    change: true
  },
  {
    label: '单位',
    prop: 'costUnit',
    change: true
  },
  {
    label: '单价',
    prop: 'price',
    change: true
  },
  {
    label: '金额',
    prop: 'amt',
    change: true,
    red: true
  },
  {
    label: '结算方式',
    prop: 'accountName',
    change: true
  },
  {
    label: '结算月份',
    prop: 'financeYymm',
    change: true
  },
  {
    label: '备注',
    prop: 'remark',
    change: true
  },
  {
    label: '扣款/补贴',
    prop: 'processStatus',
    change: true
  },
  {
    label: '结算单号',
    prop: 'balanceNo',
    change: true
  },
  {
    label: '备注信息',
    prop: 'remarkCw'
  },
  {
    label: '制单员',
    prop: 'sysUser'
  }
])

const tableHeader1 = ref([
  {
    label: '指令号',
    prop: 'lotNo'
  },
  {
    label: '费用描述',
    prop: 'costDesc'
  },
  {
    label: '单位',
    prop: 'costUnit'
  },
  {
    label: '数量',
    prop: 'qty'
  },
  {
    label: '单价',
    prop: 'price'
  },
  {
    label: '金额',
    prop: 'amt'
  },
  {
    label: '备注',
    prop: 'remark'
  },
  {
    label: '单据号码',
    prop: 'feeSlipNo',
    change: true
  },
  {
    label: '状态',
    prop: 'feeStatus',
    change: true
  },
  {
    label: '项次',
    prop: 'feeItem',
    change: true
  }
])

const tableHeader2 = ref([
  {
    label: '类型编码',
    prop: 'typeNo'
  },
  {
    label: '类型名称',
    prop: 'typeName',
    backgroundColor2: true
  },
  {
    label: '财务类型',
    prop: 'typeCw'
  }
])
</script>

<style lang="less" scoped>
h1 {
  font-size: 14px;
  margin-bottom: 5px;
}
</style>
